//
// Created by guanzhe on 16/1/5.
// Copyright (c) 2016 BMProject. All rights reserved.
//

#import "DitchManageChangeVc.h"
#import "DataModel.h"
#import "ReasonViewController.h"
#import "QudaobiangengBottomCell.h"
#import "DitchManageChangeCell.h"
#import "DetailBottomCell.h"

//渠道经理变更页面
@interface DitchManageChangeVc()<UITableViewDataSource,UITableViewDelegate>{
    OrderDealDetailOrderInfo *_orderInfo;
    OrderDealDetailOrderContentInfo *_contentInfo;
    UITableView * _tableview;
    NSMutableArray *_orderDealDetailPoolList;//OrderDealDetailPoolList 数据
}

@end

@implementation DitchManageChangeVc {

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"渠道经理变更";
    UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
    tableview.delegate = self;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableview.sectionHeaderHeight = 8.0;
    tableview.sectionFooterHeight = 8.0;
    tableview.dataSource = self;
    tableview.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 10)];

    _tableview = tableview;

    [self addSubview:tableview];


    [self requestDetail];

}
#pragma mark-UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if(_type == ORDER_EDIT_TYPE){
        return 3;
    }else{
        return 2;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        static NSString * cellId = @"DitchManageChangeTopCell";
        DitchManageChangeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell)
        {
            cell = [[[NSBundle mainBundle] loadNibNamed:cellId owner:self options:nil]lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.vc = self;
        [cell setInfo:_model];
        [cell setOrderContentInfo:_contentInfo];

        return cell;
    }
    else if(indexPath.section == 1)
    {
        static NSString * cellId = @"QudaobiangengBottomCell";
        QudaobiangengBottomCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell)
        {
            cell = [[[NSBundle mainBundle] loadNibNamed:cellId owner:self options:nil]lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell setCellInfo:_contentInfo];
        return cell;

    }else{
        static NSString *cellId = @"DetailBottomCell";
        DetailBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:cellId owner:self options:nil] lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.passBtn addTarget:self action:@selector(passClick) forControlEvents:UIControlEventTouchUpInside];
            [cell.rejectBtn addTarget:self action:@selector(rejectClick) forControlEvents:UIControlEventTouchUpInside];
        }
        return cell;
    }

}
#pragma mark-UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 180;
    }
    if(indexPath.section == 1){
        return 90;
    }
    else
    {
        return 60;
    }
}

- (void) requestDetail {
    //Type=2 类型为号卡工单时的返回报文
    [UserServices orderAuditDetailByToen:[[AppDelegate appDelegate] getUserInfo].token
                                      id:_model.id
                                    sign:_model.sign
                                    type:_model.type
                              showDialog:YES
                         completionBlock:^(int result, id responseObject) {
                             if (result == API_Request_Success) {
                                 NSDictionary *responseDict = responseObject[0];
                                 NSDictionary *orderInfoDic        = [responseDict objectForKey:@"orderInfo"];
                                 NSDictionary *orderContentInfoDic = [responseDict objectForKey:@"orderContentInfo"];
                                 NSMutableArray *poolList          = [responseDict objectForKey:@"poolList"];//数组
                                 _orderInfo = [[OrderDealDetailOrderInfo alloc] initWithDictionary:orderInfoDic error:nil];
                                 _contentInfo = [[OrderDealDetailOrderContentInfo alloc] initWithDictionary:orderContentInfoDic error:nil];
                                 [_tableview reloadData];

                             }
                         }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark-event pass
- (void)passClick
{
    DLog(@"审核通过..");
    [UserServices orderAuditOpttByToken:[[AppDelegate appDelegate] getUserInfo].token
                                     id:_model.id
                                basicId:_model.id
                                 status:@"pass"
                                  reson:@""
                             showDialog:YES
                        completionBlock:^(int result, id responseObject) {

                        }];

}

#pragma mark-event rejet
- (void)rejectClick
{
    DLog(@"审核驳回..");
    ReasonViewController * vc = [[ReasonViewController alloc]init];
    vc.isFromeOrder = YES;
    vc.orderID = _model.id;
    [self.navigationController pushViewController:vc animated:YES];
}


@end